/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.restorator.dao.implement;

import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;
import org.restorator.dao.base.ItemDao;
import org.restorator.entity.Item;
import org.restorator.exception.DataStoreException;

/**
 *
 * @author Mama
 */
public class ItemDaoMock implements ItemDao {
    ArrayList<Item> items;
    public ItemDaoMock(){
        Item i1= new Item(1, "Beer", 35.3, "Alco", "Good beer");
        Item i2= new Item(2, "Vine", 60, "Alco", "Good vine");
        items = new ArrayList<Item>();
        items.add(i1);
        items.add(i2);
    }

    public static void main(String[] args) throws DataStoreException {
        String s =new Gson().toJson(new ItemDaoMock().getAll());
        System.out.println(s);
    }

    @Override
    public List<Item> getItemsByOrderId(int id) throws DataStoreException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<Item> getItemByCategoria(int categoriaId) throws DataStoreException {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Item get(Integer id) throws DataStoreException {
        for(Item i : items){
           if(i.getItemId()==id){
               return i;
           } 
        } 
        return null;
    }

    @Override
    public Item update(Item itm) throws DataStoreException {
        for(Item i : items){
           if(i.getItemId()== itm.getItemId()){
               i.setCategoryName(itm.getCategoryName());
               i.setDescription(itm.getDescription());
               i.setItemId(itm.getItemId());
               i.setName(itm.getName());
               i.setPrice(itm.getPrice());
           } 
        } 
        return itm;
    }

    @Override
    public void delete(Item itm) throws DataStoreException {
        for(Item i : items){
           if(i.getItemId()== itm.getItemId()){
               items.remove(i);
           }
        }
    }

    @Override
    public long count() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Integer save(Item persist, Object... addParams) throws DataStoreException {
        items.add(persist);
        return persist.getItemId();
    }

    @Override
    public List<Item> getAll() throws DataStoreException {
        return items;
    }

    @Override
    public boolean exist(Integer id) {
        for(Item i : items){
           if(i.getItemId()== id){
               return true;
           }
        }
        return false;
    }
    
}
